package com.ctsi.framework.elementui.support;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;

public class TreeNode implements Serializable {

    private String id;

    private String label;

    private boolean isLeaf = false;

    private boolean disabled = false;

    private List<TreeNode> children = new ArrayList<>();

    private TreeNode(String id, String label, boolean isLeaf, boolean disabled) {
        this.id = id;
        this.label = label;
        this.isLeaf = isLeaf;
        this.disabled = disabled;
    }

    private TreeNode() {
    }

    public static TreeNode init(String id, String label, boolean isLeaf, boolean disabled){
        return new TreeNode(id,label,isLeaf,disabled);
    }

    public <T> TreeNode addTreeNode(T t , Function<T,TreeNode> func){
        this.children.add(func.apply(t));
        return this;
    }

    public <T> TreeNode addTreeNodes(T t , Function<T,List<TreeNode>> func){
        this.children.addAll(func.apply(t));
        return this;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getLabel() {
        return label;
    }

    public void setLabel(String label) {
        this.label = label;
    }

    public boolean isLeaf() {
        return isLeaf;
    }

    public void setLeaf(boolean leaf) {
        isLeaf = leaf;
    }

    public boolean isDisabled() {
        return disabled;
    }

    public void setDisabled(boolean disabled) {
        this.disabled = disabled;
    }

    public List<TreeNode> getChildren() {
        return children;
    }

    public void setChildren(List<TreeNode> children) {
        this.children = children;
    }
}
